package ace.tool.generate.code.impl.manager;

import ace.tool.generate.code.impl.generator.DefaultGenerator;
import ace.tool.generate.code.impl.generator.module.model.dto.ModuleProjectPomModel;
import ace.tool.generate.code.impl.generator.module.model.dto.ModuleProjectReadmeModel;
import ace.tool.generate.code.impl.resolver.scheme.model.bo.GenerateContext;
import lombok.SneakyThrows;

/**
 * @author caspar
 * @date 2024/1/11 10:12 module project generator  manager
 */
public class ModuleProjectManager {
  private final GenerateContext context;

  public ModuleProjectManager(GenerateContext context) {
    this.context = context;
  }

  @SneakyThrows
  public void generate() {
    this.generatePom();

    this.generateReadme();
  }

  private void generateReadme() {
    ModuleProjectReadmeModel model = ModuleProjectReadmeModel.builder().build();
    String templateFile = "/schema/module-project/ModuleProjectReadme.ftl";
    String outputFileFullName = context.getModuleProject().getInfo().getReadmeFileFullName();
    new DefaultGenerator(templateFile, outputFileFullName).generate(model);
  }

  private void generatePom() {
    ModuleProjectPomModel model =
        ModuleProjectPomModel.builder()
            .apiProjectMavenArtifactId(
                context.getModuleProject().getApiProject().getInfo().getMavenArtifactId())
            .sdkProjectMavenArtifactId(
                context.getModuleProject().getSdkProject().getInfo().getMavenArtifactId())
            .coreProjectMavenArtifactId(
                context.getModuleProject().getCoreProject().getInfo().getMavenArtifactId())
            .projectMavenArtifactId(context.getModuleProject().getInfo().getMavenArtifactId())
            .build();
    String templateFile = "/schema/module-project/ModuleProjectPom.ftl";
    String outputFileFullName = context.getModuleProject().getInfo().getPomFileFullName();
    new DefaultGenerator(templateFile, outputFileFullName).generate(model);
  }
}
